package com.openspring.framework.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResultUtils {
	
	public static Map<String, Object> success() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("success", true);
		return map;
	}
	
	public static Map<String, Object> failure(String msg) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("success", false);
		map.put("message", msg);
		return map;
	}
	
	public static Map<String, Object> data(Object entity) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("data", entity);
		map.put("success", true);
		return map;
	}
	
	public static Map<String, Object> datas(int totalCount, List<?> entities) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("totalCount", totalCount);
		map.put("datas", entities);
		map.put("success", true);
		return map;
	}
	
	public static Map<String, Object> datas(List<?> entities) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("totalCount", entities.size());
		map.put("datas", entities);
		map.put("success", true);
		return map;
	}
	
	public static Map<String, Object> datas(Object entity, List<?> entities) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("data", entity);
		map.put("datas", entities);
		map.put("success", true);
		return map;
	}
	
	public static Map<String, Object> tree(Object node) {
		Map<String, Object> root = new HashMap<String, Object>();
		root.put("children", node);
		root.put("success", true);
		return root;
	}
}
